//index.js
//获取应用实例
const app = getApp()
var yonghu = {
  id: '00001',
  touxiang: "http://wx.qlogo.cn/mmhead/INpFh6FtwI8kvHUFLL5t37cG9ib5IHkOAXXia9I1WVdac/132",
  name: 'King  Winter',
  money: '300',
  level: "9",
  ranking: "1",
  isChecked: false
};
wx.setStorage({
  key: "yonghu",
  data: yonghu
})
Page({
  data: {
    userInfo: { nickName: "King  Winter", avatarUrl: "http://wx.qlogo.cn/mmhead/INpFh6FtwI8kvHUFLL5t37cG9ib5IHkOAXXia9I1WVdac/132", level: "9", ranking: "1"},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    rankingList: [
      {
        ranking:'1',
        friendImg: 'http://wx.qlogo.cn/mmhead/INpFh6FtwI8kvHUFLL5t37cG9ib5IHkOAXXia9I1WVdac/132',
        friendName: 'King  Winter',
        duanwei: '童生',
        level: '9',
        isown: true
      },
      {
        ranking: '2',
        friendImg: '../../images/saber.jpg',
        friendName: '阴阳师',
        duanwei: '学童',
        level: '7 ',
        isown: false
      }
    ]
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../game/game'
    });
  }, 
  onReady: function () {
    // 页面渲染完成
    // 实例化一个动画
    var that = this;
    var animationData = wx.createAnimation({
      duration: 400, // 默认为400   动画持续时间，单位ms
      timingFunction: 'ease-in-out',
    });
    var animationStartData = wx.createAnimation({
      duration: 400, // 默认为400   动画持续时间，单位ms
      timingFunction: 'ease-in-out',
    });
    //动画的脚本定义必须每次都重新生成，不能放在循环外
    animationStartData.scale(1.2).step({ duration: 400 }).scale(1).step({ duration: 400 });
    // 更新数据
    that.setData({
      // 导出动画示例
      animationStartData: animationStartData.export(),
    })
    setInterval(function () {
      //动画的脚本定义必须每次都重新生成，不能放在循环外
      animationStartData.scale(1).step({ duration: 200 }).scale(1.2).step({ duration: 400 });
      // 更新数据
      that.setData({
        // 导出动画示例
        animationStartData: animationStartData.export(),
      })
    }.bind(that), 800);
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      });

      console.log(rankingList);
    }
  }
})
